/*-----------------------------------------------------------------------------
	The contents of this file are subject to the Mozilla Public License
	Version 1.1 (the "License"); you may not use this file except in
	compliance with the License.You may obtain a copy of the License at
	http://www.mozilla.org/MPL/MPL-1.1.html
	
	Software distributed under the License is distributed on an "AS IS"
	basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
	License for the specific language governing rights and limitations
	under the License.
	
	The Original Code is Fever Framework code.
	
	The Initial Developer of the Original Code is Romain Ecarnot.
	Portions created by Initial Developer are Copyright (C) 2006
	the Initial Developer. All Rights Reserved.
	
	Contributor(s):
	
	Unless required by applicable law or agreed to in writing, software
	distributed under the License is distributed on an "AS IS" BASIS,
	WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
	See the License for the specific language governing permissions and
	limitations under the License.
-----------------------------------------------------------------------------*/

import org.aswing.CursorManager;

import fvaswing.components.cursors.FvAbstractCursor;

/**
 * A 'color picker' cursor.
 * 
 * <p>Used by the {@link fvaswing.components.FvColorChooser} component.
 * 
 * @author Romain Ecarnot
 */
class fvaswing.components.colorchooser.FvColorPickerCursor extends FvAbstractCursor
{
	//-------------------------------------------------------------------------
	// Constants definition
	//-------------------------------------------------------------------------
	
	/** Color used if {@link #color} is not defined. */
	public static var CURSOR_COLOR : Number = 0x000000;
	
	
	//-------------------------------------------------------------------------
	// Private properties
	//-------------------------------------------------------------------------
	
	private static var _instance : FvColorPickerCursor;
	
	private var _color : Number;
	
	
	//-------------------------------------------------------------------------
	// Public Properties
	//-------------------------------------------------------------------------
	
	/** Cursor color. */
	public function get color() : Number { return _color; }
	public function set color ( n : Number ) : Void { _color = n;	}
	
	
	//-------------------------------------------------------------------------
	// Public API
	//-------------------------------------------------------------------------
	
	/**
	 * Returns a unique <strong>FvCursor</strong> instance.
	 */
	public static function getInstance() : FvColorPickerCursor
	{
		if( _instance == undefined ) _instance = new FvColorPickerCursor();
		return _instance;	
	}
	
	/**
	 * Shows cursor and hides the system cursor. 
	 */
	public static function show() : Void
	{
		CursorManager.showCustomCursor( getInstance() );
		CursorManager.hideSystemCursor();	
	}
	
	/**
	 * Hides cursor and shows the default system cursor. 
	 */
	public static function hide() : Void
	{
		CursorManager.hideCustomCursor( getInstance() );
		CursorManager.showSystemCursor();
	}
	
	/**
	 * Constructor.
	 * 
	 * <p>Cursor properties are initialized with constants values.
	 * <ul>
	 *   <li>{@link #CURSOR_COLOR}</li>
	 * </ul>
	 */
	public function FvColorPickerCursor()
	{
		super();
		
		_color = CURSOR_COLOR;
	}	
	
	/**
	 * Concrete drawing implementation.
	 */
	public function repaint() : Void
	{
		_paintBasicCursor();
		
		_applyFilter();
	}
	
	
	//-------------------------------------------------------------------------
	// Private implementation
	//-------------------------------------------------------------------------
		
	private function _paintBasicCursor() : Void
	{
		var w : Number = 4;
		
		_container.lineStyle( 2, _color, 100 );
		_container.moveTo( -w, 0 );
		_container.lineTo( w, 0 );
		_container.moveTo( 0, -w );
		_container.lineTo( 0, w );
	}
	
	private function _applyFilter() : Void
	{
		// no filter here, only a pure cross cursor
	}
}